﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;


namespace Miao.Stand
{
    /// <summary>
    /// 枯萎穿心攻击
    /// </summary>
    public class SecondBombAbility : StandVerbAbility
    {
        public KillerQueenStand killerQueen
        {
            get
            {
                return stand as KillerQueenStand;
            }
        }

        public SecondBombAbility(StandPawn stand) : base(stand)
        {

        }
        Command_StandAbilityVerbTarget command_Target;

        Command_Action command_Action;
        public override void Init()
        {
            base.Init();
            command_Target = new Command_StandAbilityVerbTarget(this);
            SetDefField(command_Target);

            command_Action = new Command_Action();
            command_Action.defaultLabel = "回收枯萎穿心攻击".Translate();
            command_Action.defaultDesc = def.description;
            command_Action.icon = Stand.ModSingleton.LoadIcon(def.iconPath + "回收");
            command_Action.Order = 20.2f;
            command_Action.activateSound = SoundDefOf.Checkbox_TurnedOn;
            command_Action.action = RecoverySheeHeartAttack;
        }
        /// <summary>
        /// 回收枯萎穿心攻击
        /// </summary>
        private void RecoverySheeHeartAttack()
        {
       
                if (!(killerQueen.SheeHeartAttack.CurJobDef == StandJobDefOf.ReturnToMaster))
                {
                    Job job = JobMaker.MakeJob(StandJobDefOf.ReturnToMaster, killerQueen);
                    killerQueen.SheeHeartAttack.jobs.StartJob(job,JobCondition.Succeeded);
                }
        }

        public override Gizmo DrawGizmo()
        {
            if (killerQueen.SheeHeartAttack == null)
            {
                bool disabled = PowerCostEnough(command_Target) & CooldownComplete(command_Target) & HasLeftHand(command_Target);
                return command_Target;
            }
            else
            {
                if(killerQueen.SheeHeartAttack.Map!= killerQueen.Map)
                {
                    command_Action.Disable("必须在同一张地图".Translate());
                }

                return command_Action;
            }
        }

        public bool HasLeftHand(Command_StandAbilityVerbTarget commandStand)
        {
            List<Hediff> hediffs = stand.owner.health.hediffSet.hediffs;
            for (int i = 0; i < hediffs.Count; i++)
            {
                Hediff_MissingPart hediff_MissingPart;
                if ((hediff_MissingPart = hediffs[i] as Hediff_MissingPart) != null)
                {
                    foreach (BodyPartGroupDef leftHand in hediff_MissingPart.Part.groups)
                    {
                        if (leftHand == BodyPartGroupDefOf.LeftHand)
                        {
                            commandStand.disabledReason = "左手必须完好".Translate();
                            return false;
                        }
                    }
                }
            }
            return true;
        }
    }
}
